<?php
namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class OrderItemResource extends JsonResource
{
    public function toArray($request)
    {
	    $resource = $this->resource;
	    $number = $resource->order->number;
        return [
        	'id' => (int)$resource->id,
	        'order_id' => (int)$resource->order_id,
	        'product_id' => (int)$resource->product_id,
	        'product_sku_id' => (int)$resource->product_sku_id,
	        'product_title' => $resource->product_title,
	        'product_cover' => img_path($resource->product_cover),
	        'sku_name' => $resource->sku_name,
	        'sku_pic' => img_path($resource->sku_pic),
	        'amount' => (int)$resource->amount,
	        'price' => $resource->price,
	        'total_amount' => $resource->total_amount,
	        'delivery_status' => $resource->delivery_status,
	        'delivery_data' => $resource->delivery_data,
	        'created_at' => (string)$resource->created_at,
	        'number' => $number,
	        'has_commented' => $resource->has_commented,
	      /*  'order' => new OrderResource($this->whenLoaded('order')),*/
	        'product' => new ProductResource($this->whenLoaded('product')),
	        'sku' => new ProductSkuResource($this->whenLoaded('sku')),
        ];
    }
}
